package com.bawei.module_live.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import com.bawei.module_live.R

class RedPacketGrabDialog(
    context: Context,
    private val onGrabClick: () -> Unit,
    private val onCloseClick: () -> Unit
) : Dialog(context) {

    private lateinit var btnGrabRedPacket: Button
    private lateinit var ivClose: ImageView
    private lateinit var tvTitle: TextView
    private lateinit var tvDescription: TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        // 设置窗口属性
        window?.apply {
            setLayout(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT
            )
            setBackgroundDrawableResource(android.R.color.transparent)
            // 设置透明背景
            setBackgroundDrawableResource(android.R.color.transparent)
            // 设置无标题
            requestFeature(android.view.Window.FEATURE_NO_TITLE)
            // 设置半透明背景
            addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
            attributes = attributes.apply {
                dimAmount = 0.5f
            }
        }
        
        val view = LayoutInflater.from(context).inflate(R.layout.dialog_red_packet_grab, null)
        setContentView(view)
        
        initViews(view)
        setupListeners()
    }

    private fun initViews(view: View) {
        btnGrabRedPacket = view.findViewById(R.id.btn_grab_red_packet)
        ivClose = view.findViewById(R.id.iv_close)
        tvTitle = view.findViewById(R.id.tv_title)
        tvDescription = view.findViewById(R.id.tv_description)
    }

    private fun setupListeners() {
        btnGrabRedPacket.setOnClickListener {
            onGrabClick()
            dismiss()
        }
        
        ivClose.setOnClickListener {
            onCloseClick()
            dismiss()
        }
    }

    // 设置标题
    fun setTitle(title: String) {
        tvTitle.text = title
    }

    // 设置描述
    fun setDescription(description: String) {
        tvDescription.text = description
    }
} 